
import scipy.io.wavfile as wavfile
import matplotlib.pyplot as plt
import numpy as np
import pyaudio
volume = 0.1
fs = 44100
f = 2000.0
duration = 180.0
chs = 2


samples = np.sin(2*np.pi*f*(np.arange(fs*duration)/fs))
samples = samples.astype(np.float32)

samples_int32 = ((samples) *volume*(2.0**31)).astype(np.int32)

sample = np.c_[samples_int32, samples_int32]  # two channels
wavfile.write("sine.wav", fs, sample)

# audio play
# p = pyaudio.PyAudio()

# stream = p.open(format=pyaudio.paInt32,
                # channels=chs,
                # rate=fs,
                # output=True)

# stream.write(samples_uint32)

# stream.stop_stream()
# stream.close()

# p.terminate()
